﻿using Microsoft.AspNetCore.Http.HttpResults;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.Extensions;
using VOL.Core.Utilities;
using VOL.Domain.Infrastructure;
using VOL.Domain.IServices;
using VOL.Entity.DomainModels;

namespace VOL.Domain.Services
{
    public class SchedulingManagementServices : ISchedulingManagementServices
    {
        private readonly IBaseRepository<Holidays> _holidaysbaseRepository;

        public SchedulingManagementServices(IBaseRepository<Holidays> holidaysbaseRepository)
        {
            _holidaysbaseRepository = holidaysbaseRepository;
        }

        public Task<WebResponseContent> GetHolidays()
        {
            var result = new WebResponseContent();
            var HolidaysList = _holidaysbaseRepository.GetAll();
            result.OK("查询节假日成功", HolidaysList);
            return Task.FromResult(result);

        }
        public async Task<WebResponseContent> CreateUpdateHolidays(Holidays holidays)
        {
            var result= new WebResponseContent();
            if (holidays.id !=0)
            {
                var holidy= _holidaysbaseRepository.GetAll().FirstOrDefault(a=>a.id==holidays.id);
                holidy.HolidaysTime = holidays.HolidaysTime;
                holidy.HolidaysType = holidays.HolidaysType;
                var entity = await _holidaysbaseRepository.Update(holidy);
            }
            else
            {
                var entity = await _holidaysbaseRepository.Add(holidays);
            }
           
            return  result.OK("成功", null);
        }
    }
}
